#XML RPC
from django.shortcuts import render_to_response
from models import Twit
from django.forms import ModelForm

def home(request):
    return render_to_response('home.html',
        {'twits': Twit.objects.all().order_by('-created')})

class TwitForm(ModelForm):
    class Meta:
        model = Twit
        
def twit(text):
    f = TwitForm({'text':text})
    if f.is_valid():
        t = f.save()
        return True, t.id
    else:
        return False, f.errors.as_text
    
def twit_count():
    return Twit.objects.all().count()
